//
//  ShapeView.m
//  ModuleTesting
//
//  Created by duc nguyen van on 8/31/11.
//  Copyright 2011 STU. All rights reserved.
//

#import "ShapeView.h"


@implementation ShapeView
@synthesize reView,delegate;

#pragma mark -
#pragma mark menuControl

-(void)copyItem:(id)sender{
	NSLog(@"has copy");
}

-(void)deleteItem:(id)sender{
	
}

-(void)cloneItem:(id)sender{
	
}

-(void)callMenu{
	[self becomeFirstResponder];
	UIMenuController *menuControl = [UIMenuController sharedMenuController];
	UIMenuItem *menuCopy = [[UIMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyItem:)];
	UIMenuItem *menuDelete = [[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(deleteItem:)];
	UIMenuItem *menuClone = [[UIMenuItem alloc] initWithTitle:@"Clone" action:@selector(cloneItem:)];
	
	[menuControl setMenuItems:[NSArray arrayWithObjects:menuCopy, menuDelete, menuClone, nil]];
	[menuControl setTargetRect:CGRectMake(0	, 0, self.frame.size.width, 0) inView:self];
	[menuControl setMenuVisible:YES animated:YES];
	
	[menuCopy release];
	[menuDelete release];
	[menuClone release];
}

#pragma mark -
#pragma mark delegateResizeView

-(void)hasEndedMove{
	[self callMenu];
}

#pragma mark -
#pragma mark delegateView

-(BOOL)canBecomeFirstResponder{
	return YES;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	NSLog(@" has began");
	reView.hidden = NO;
	[delegate setSelectedShape:self];
	
	[self callMenu];
}
#pragma mark -
#pragma mark init

- (id)initWithSizeForResizeView:(CGSize)s{
	self = [super init];
	if (self) {
		//
		reView = [[ResizeView alloc] initWithFrame:CGRectMake(0, 0, s.width, s.height)];
		reView.backgroundColor = [UIColor clearColor];
		reView.delegate = self;
		reView.hidden = YES;
	}
	return self;
}

- (id)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

- (void)dealloc {
	[reView release];
    [super dealloc];
}


@end
